<?php
namespace Crm\Api;

use PhalApi\Api;
use Auth\Api\Token as Token;
use Crm\Domain\Coupon as DomainCoupon;

/**
 * Coupon优惠券服务
 *
 * @author: luodong <751450467@qq.com> 2020-06-24
 */

class Coupon extends Api {

    /**
     * token对象
     */
    public $token;

    /**
     * 当前用户信息
     */
    public $user;

    public function __construct()
    {
        //允许所有域名发起的跨域请求
        header('Access-Control-Allow-Origin: *');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
        //header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
        //header('Access-Control-Allow-Headers:Authorization,content-type');  //响应头 请按照自己需求添加。
        //$this->di = \PhalApi\DI();
        $this->token = new Token();

    }

	public function getRules() {
        return array(
            'couponList' => array(
                'project_id'=> array('name' => 'project_id', 'type'=>'int','default'=>0,'require'=>false,'desc'=>'项目id'),
                'mall_id'=> array('name' => 'mall_id', 'type'=>'int','require'=>true,'desc'=>'默认商城ID')
            )
        );
	}

    /**
     * 优惠券列表
     * @desc 优惠券列表
     * @return array userIntent 优惠券列表
     * @return int time 当前时间戳
     */
    public function couponList(){
        //$this->user = $this->token->checkToken();
        error_log("add!", 0);

        $params =  \PhalApi\DI()->request->getAll();
        $param['user_id'] = $this->user['user_id'];
        $domain = new DomainCoupon();
        $score = $domain->search($params);
        return $score;
    }


}
